package com.ymm.lulutong.domain.impl;

import com.ymm.lulutong.constant.ResultCodeEnum;
import com.ymm.lulutong.domain.ShipperFriendDomainService;
import com.ymm.lulutong.entity.ShipperFriendRelationship;
import com.ymm.lulutong.mapper.ShipperFriendRelationshipMapper;
import com.ymm.lulutong.mapper.ShipperProfileMapper;
import com.ymm.lulutong.response.ShipperInfoResponse;
import com.ymm.lulutong.utils.Result;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

@Service
public class ShipperFriendDomainServiceImpl implements ShipperFriendDomainService {
    @Resource
    ShipperProfileMapper shipperProfileMapper;

    @Resource
    ShipperFriendRelationshipMapper shipperFriendRelationshipMapper;

    @Override
    public Result<ShipperInfoResponse> findShipper(String phoneNumber) {
        if (Objects.isNull(phoneNumber)) {
            return Result.fail(null, ResultCodeEnum.PARAMETER_NULL_ERROR.getCode(), ResultCodeEnum.PARAMETER_NULL_ERROR.getMessage());
        }
        ShipperInfoResponse shipperInfo;
        try {
            shipperInfo = shipperProfileMapper.getShipperInfoByPhoneNumber(phoneNumber);
            if (Objects.isNull(shipperInfo)) {
                return Result.fail(null, ResultCodeEnum.FAIL.getCode(), "无此货主！");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return Result.fail(null, ResultCodeEnum.DATABASE_ERROR.getCode(), "系统繁忙");
        }
        return Result.success(shipperInfo);
    }

    @Override
    public Result<Boolean> sendFriendInvitation(Long shipperIdFrom, Long shipperIdTo) {
        if (shipperIdFrom.compareTo(shipperIdTo) > 0) {
            Long temp = shipperIdFrom;
            shipperIdFrom = shipperIdTo;
            shipperIdTo = temp;
        }
        ShipperFriendRelationship shipperFriendRelationship = new ShipperFriendRelationship();
        shipperFriendRelationship.setShipperId1(shipperIdFrom);
        shipperFriendRelationship.setShipperId2(shipperIdTo);
        shipperFriendRelationship.setStatusType(2);

        return null;
    }

    @Override
    public Result<Boolean> responseToFriendInvitation(Long relationshipId, Boolean accept) {
        return null;
    }

    @Override
    public Result<List<ShipperInfoResponse>> getFriendsByShipperId(Long shipperId) {
        return null;
    }
}
